package org.xxpay.pay.channel.payeasepay.demo;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.xxpay.pay.channel.payeasepay.demo.CFCA.MerchantX509Cert;
import org.xxpay.pay.channel.payeasepay.util.XmlUtils;

import javax.ws.rs.core.MultivaluedMap;
import java.util.Map;


public class Status {
	
	private static final String SINGLE_CHECK_URL = "https://pay.yizhifubj.com/merchant/virement/mer_payment_status_utf8.jsp";

	public static void main(String[] args) throws Exception {
		String XML = CheckCard(); //
		
		System.out.println("-----------------------------------------------------"); 
		System.out.println(XML); //


	}



	public static String CheckCard() throws Exception {
		System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
		Client cc = Client.create();
		WebResource rr = cc.resource(SINGLE_CHECK_URL);

		MultivaluedMap queryParams = new MultivaluedMapImpl();
		
		String v_mid = "7606";//
		String v_data ="C2001";
		
		String v_version ="1.0";
		String str=v_mid+v_data;

		
		String pfxFile = "D:/certificate/payease/cfca_private.pfx";//
	    String pfxPassword = "lh121121";
	    String aliasPassword = "lh121121";
	    String aliasName = "{3dfcbb2d-bb3d-4350-9010-33de8cdb076c}";
	    String sign = MerchantX509Cert.sign(str, pfxFile, aliasName, pfxPassword, aliasPassword);
		System.out.println(sign) ;
		System.out.println("--------------------------------------------------") ;
		queryParams.add("v_mid", v_mid); 
		queryParams.add("v_data",java.net.URLEncoder.encode(v_data, "GBK"));
		queryParams.add("v_version", v_version);
		queryParams.add("v_mac", sign);
		String ret = rr.queryParams(queryParams).post(String.class);
		Map<String,String> resultMap = XmlUtils.xml2Map(ret);
		System.out.println(resultMap.get("status") + "_________" + resultMap.get("statusdesc") + "_________" + resultMap.get("v_fee") + "_________" + resultMap.get("transdesc"));
		return ret;
		
	}

}
